﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KnBinarySerializer.Brick
{
    internal class StringFormatter : IFormatter
    {
        public Type GetHandleType()
        {
            return typeof(string);
        }

        public byte GetKey()
        {
            return 21;
        }
        public bool IsFixLen()
        {
            return false;
        }
        public object ReadBytes(BianaySerializeManager content, int maxLen, Type type)
        {
            byte[] buffer = content.ReadBytes(maxLen);
            return System.Text.Encoding.UTF8.GetString(buffer);
        }

        public int WriteBytes(BianaySerializeManager serial, object obj)
        {
            byte[] content = System.Text.Encoding.UTF8.GetBytes((string)obj);
            serial.Write(content);
            return content.Length;
        }
    }
}
